<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>粘性定位</title>
  <style>
    body {
      height: 2000px;
    }

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    .header {
      position: sticky;
      top: 0;
      margin: 0 auto;
      width: 1200px;
      height: 44px;
      background-color: #f0f;
    }

    .banner {
      margin: 0 auto;
      width: 1200px;
      height: 400px;
      background-color: #0ff;
    }
  </style>
</head>

<body>
  <div class="header"></div>
  <div class="banner"></div>
</body>

</html>